package com.ruoyi.bankcardtable.service.impl;

import com.ruoyi.bankcardtable.domain.BankCardTable;
import com.ruoyi.bankcardtable.domain.vo.BankCardTableVO;
import com.ruoyi.bankcardtable.mapper.BankCardTableMapper;
import com.ruoyi.bankcardtable.service.BankCardTableService;
import com.ruoyi.bankinfo.domain.BankInfo;
import com.ruoyi.bankinfo.mapper.BankInfoMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BankCardTableServiceImpl implements BankCardTableService {

    @Autowired
    private BankCardTableMapper bankCardTableMapper;
    @Autowired
    private BankInfoMapper bankInfoMapper;

    @Override
    public List<BankCardTableVO> selectBankCard(BankCardTable bankCardTable) {
        ArrayList<BankCardTableVO> bankCardTableVOS = new ArrayList<>();
        List<BankCardTable> bankCardTables = bankCardTableMapper.selectBankCardTableList(bankCardTable);
        for (BankCardTable cardTable : bankCardTables) {
            BankCardTableVO bankCardTableVO = new BankCardTableVO();
            BeanUtils.copyProperties(cardTable, bankCardTableVO);
            BankInfo bankInfo = new BankInfo();
            bankInfo.setBankCode(cardTable.getBankCode());
            BankInfo bankInfo1 = bankInfoMapper.selectBankInfoList(bankInfo).get(0);
            bankCardTableVO.setBankInfo(bankInfo1);
            bankCardTableVOS.add(bankCardTableVO);
        }
        return bankCardTableVOS;
    }

    /**
     * 新增银行卡
     *
     * @param bankCardTable
     * @return
     */
    @Override
    public String insertBankCard(BankCardTable bankCardTable) {
        bankCardTable.setCreateTime(DateUtils.getNowDate());
        bankCardTableMapper.insertBankCard(bankCardTable);
        return "添加成功";
    }
}
